﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="admin_Modules_NewsEvent_News_Default" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">--%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="/admin/resources/js/base.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">

        var commandHandler = function (cmd, record) {
            switch (cmd) {
                case "edit":
                    top.createWindow('addOrEditNews', '/admin/Modules/newsevent/News/addoredit.aspx?cbFX=reloadNews&Id=' + record.data.ID + "&tId=" + getTabPanelID(), 'Sửa tin bài', 960, 560, true);
                    break;
                case "detail":
                    //top.createWindow('viewDetail', '/tin-tuc/' + record.data.ID + '/xem-chi-tiet.htm', 'Xem chi tiết', 960, 560, true);
                    window.open('/tin-tuc/' + record.data.ID + '/xem-chi-tiet.htm', '_blank');
                    break;
            }
        }

        var date = function (value, p, record) {

            if (value == null) return "";
            value = value.replace(" ", "T");
            var temp = value.split("T");
            var date = temp[0].split("-");
            var dateStr = date[2] + "/" + date[1] + "/" + date[0];
            return dateStr;
        }


        var HotRerender = function (value, p, record) {
            if (value == true) return "<img src='/admin/resources/images/bullet_green.png' alt='' />";
            return "<img src='/admin/resources/images/bullet_red.png' alt='' />";
        }


        var applyFilter = function () {
            if (txtFilter.getValue() != '') {
                PagingToolBar1.changePage(1);
            }
        }

        var clearFilter = function () {

            var hasFilter = false;
            if (txtFilter.getValue() != '') {
                hasFilter = true;
            }

            if (hasFilter) {
                txtFilter.setValue('');
                PagingToolBar1.changePage(1);
            }

        }

        var ClickNode = function (node) {
            hdnCategoryId.setValue(node.id);
            PagingToolBar1.changePage(1);
        }



        var rowSelect = function (sl, index, record) {
            var selectRows = sl.grid.getRowsValues({ selectedOnly: true });
            var count = selectRows.length;
            btnDelete.setDisabled(count == 0);
        }

        var checkNoneAll = function (model) {
            var count = model.getSelections().length;
            btnDelete.setDisabled(count == 0);

        }

        var rowDeSelect = function (sl, index, record) {
            var selectRows = sl.grid.getRowsValues({ selectedOnly: true });
            var count = selectRows.length;
            btnDelete.setDisabled(count == 0);
        }

        var reloadNews = function () {
            PagingToolBar1.changePage(1);
        }

        function confirmDelete() {
            parent.Ext.Msg.confirm('Xác nhận', '<span style="color:red;text-align:center;">Xóa tin bài?</span>', function (btn) {
                if (btn == "yes") {
                    btnDoDelete.fireEvent('click', null);
                }
            });
        }

        function showAll() {
            hdnCategoryId.setValue(0);
            PagingToolBar1.changePage(1);
        }
        
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ScriptManager2" runat="server">
    </ext:ResourceManager>
    <ext:Hidden ID="hdnCategoryId" Text="0" runat="server">
    </ext:Hidden>
    <ext:Viewport ID="ViewPort2" runat="server" Layout="BorderLayout">
        <Items>
            <ext:TreePanel ID="tpListNewsCategory" runat="server" AutoScroll="true" Border="true"
                Margins="5 5 5 5" Region="West" Icon="PageCopy" Collapsible="true" Collapsed="false"
                Title="Menu tin bài" BodyBorder="true" BodyStyle="text-align:left;" Width="220"
                SingleExpand="false">
                <Listeners>
                    <Click Handler="ClickNode(node)" />
                </Listeners>
            </ext:TreePanel>
            <ext:Panel ID="pnDetail" runat="server" Title="Danh sách tin bài" Icon="Newspaper"
                Layout="fit" Margins="5 5 5 0" Region="Center">
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server" Flat="false">
                        <Items>
                            <ext:Button runat="server" Icon="ApplicationViewColumns" Text="Tất cả" ID="btnViewAll">
                                <Listeners>
                                    <Click Handler="showAll();" />
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarSeparator>
                            </ext:ToolbarSeparator>
                            <ext:Button Text="Xóa" Icon="Delete" ID="btnDelete" Disabled="true">
                                <Listeners>
                                    <Click Handler="confirmDelete();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button Text="Xóa" Icon="Delete" ID="btnDoDelete" Disabled="true" Hidden="true"
                                HideMode="Offsets">
                                <DirectEvents>
                                    <Click OnEvent="Delete" Before="parent.Ext.Msg.wait('Đang cập nhật dữ liêu...', 'Saving');    "
                                        Success="parent.Ext.Msg.hide();">
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                            <ext:ToolbarSpacer>
                            </ext:ToolbarSpacer>
                            <ext:ToolbarSpacer>
                            </ext:ToolbarSpacer>
                            <ext:ToolbarFill>
                            </ext:ToolbarFill>
                            <ext:Label Icon="Find" Text="Tìm kiếm">
                            </ext:Label>
                            <ext:ToolbarSpacer ID="ToolbarSpacer2" runat="server" />
                            <ext:TextField ID="txtFilter" runat="server" EmptyText="Tiêu đề hoặc tác giả" />
                            <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" />
                            <ext:Button ID="tlbSearch_u" runat="server" Icon="Zoom">
                                <Listeners>
                                    <Click Handler="applyFilter();" />
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarSeparator />
                            <ext:Button ID="tblRefesh" runat="server" Icon="ArrowRefresh">
                                <Listeners>
                                    <Click Handler="clearFilter();" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Items>
                    <ext:GridPanel ID="GridPanel1" runat="server" StripeRows="true" Frame="false" Header="false"
                        Border="false" TrackMouseOver="true" Title="Danh sách tin bài" AutoExpandColumn="Title">
                        <Store>
                            <ext:Store ID="storeNewsArticle" runat="server" AutoLoad="true">
                                <Reader>
                                    <ext:JsonReader Root="data" TotalProperty="total" IDProperty="ID">
                                        <Fields>
                                            <ext:RecordField Name="ID" />
                                            <ext:RecordField Name="Name" />
                                            <ext:RecordField Name="IsOnTop" />
                                            <ext:RecordField Name="IsHotInSite" />
                                            <ext:RecordField Name="Author" />
                                            <ext:RecordField Name="CreatedOn" Type="Date" DateFormat="M$">
                                                
                                            </ext:RecordField>
                                            <ext:RecordField Name="IsActive" />
                                            <ext:RecordField Name="CategoryId" />
                                            <ext:RecordField Name="IsInSlideShow" />
                                        </Fields>
                                    </ext:JsonReader>
                                </Reader>
                                <AutoLoadParams>
                                    <ext:Parameter Name="start" Value="0" Mode="Raw" />
                                    <ext:Parameter Name="limit" Value="20" Mode="Raw" />
                                </AutoLoadParams>
                                <BaseParams>
                                    <ext:Parameter Name="filter" Value="#{txtFilter}.getValue()" Mode="Raw" />
                                    <ext:Parameter Name="newsCatetoryId" Value="#{hdnCategoryId}.getValue()" Mode="Raw">
                                    </ext:Parameter>
                                </BaseParams>
                                <Proxy>
                                    <ext:HttpProxy Method="GET" Json="true" Url="Handler.ashx" />
                                </Proxy>
                                <Listeners>
                                    <CommitFailed Handler="Ext.Msg.alert('Lỗi cập nhật', 'Reason: ' + msg)" />
                                    <SaveException Handler="Ext.Msg.alert('Lõi cập nhật', e.message || e)" />
                                </Listeners>
                            </ext:Store>
                        </Store>
                        <ColumnModel ID="ColumnModel1" runat="server">
                            <Columns>
                                <ext:RowNumbererColumn Header="STT" Width="30" Align="Center" />
                                <ext:CommandColumn ButtonAlign="Center" Align="Center" Resizable="true" Header="Xem"
                                    Wrap="true" Width="35">
                                    <Commands>
                                        <ext:GridCommand Icon="Folder" CommandName="detail" ToolTip-Text="<b>Xem</b>" />
                                    </Commands>
                                </ext:CommandColumn>
                                <ext:CommandColumn ButtonAlign='Center' Align="Center" Width="35" Header="Sửa">
                                    <Commands>
                                        <ext:GridCommand Icon="TableEdit" CommandName="edit" ToolTip-Text="<b style='color:blue;'>Sửa</b>">
                                        </ext:GridCommand>
                                    </Commands>
                                </ext:CommandColumn>
                                <ext:Column Header="Tiêu đề" DataIndex="Name" Sortable="true" Width="112" ColumnID="Title">
                                </ext:Column>
                                <ext:Column Header="Tác giả" DataIndex="Author">
                                </ext:Column>
                                <ext:DateColumn Width="100" Header="Ngày tạo" DataIndex="CreatedOn" Format="dd/MM/yyyy HH:mm" />
                                <ext:Column Header="Trang chủ" DataIndex="IsHotInSite" Width="80" Align="Center"
                                    Resizable="false" Hideable="false">
                                    <Renderer Fn="HotRerender" />
                                </ext:Column>
                                <ext:Column Header="Hiển thị" DataIndex="IsActive" Width="80" Align="Center" Resizable="false"
                                    Hideable="false">
                                    <Renderer Fn="HotRerender" />
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <SelectionModel>
                            <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server">
                                <Listeners>
                                    <RowSelect Fn="rowSelect" />
                                    <RowDeselect Fn="rowDeSelect" />
                                    <SelectionChange Fn="checkNoneAll" />
                                </Listeners>
                            </ext:CheckboxSelectionModel>
                        </SelectionModel>
                        <LoadMask ShowMask="true" Msg="Đang nạp dữ liệu, vui lòng chờ ..." />
                        <SaveMask ShowMask="true" Msg="Đang cập nhật dữ liệu, vui lòng chờ..." />
                        <Listeners>
                            <Command Handler="commandHandler(command,  record);" />
                        </Listeners>
                    </ext:GridPanel>
                </Items>
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolBar1" runat="server" StoreID="storeNewsArticle"
                        PageSize="20" BeforePageText="Trang&nbsp;" PrevText="Trước" FirstText="Đầu" AfterPageText=""
                        EmptyMsg="Hiện tại chưa có tin bài nào" RefreshText="Làm mới" LastText="Cuối"
                        NextText="Tiếp" DisplayMsg="{0}-{1}/{2}" />
                </BottomBar>
            </ext:Panel>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>
